<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>登录页面</title>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css" media="all">
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/plugins/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
		<script src="${pageContext.request.contextPath}/layui/layui.js" type="text/javascript"></script>
		<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.js" type="text/javascript"></script>
	</head>
	
	<body class="layui-layout-login">
	<div class="login-bg">
	    <div class="cover"></div>
	</div>
	<div class="login-content" >
	    <h1 class="login-box-title"><i class="fa fa-fw fa-user"></i>登录</h1>

	    <form>
	        <div class="layui-form-item">
	            <label class="layui-icon layui-icon-username" for="username"></label>
	            <input class="layui-input" type="text" name="username" id="username" placeholder="用户名">
	        </div>
			
	        <div class="layui-form-item">
	            <label class="layui-icon layui-icon-password" for="password"></label>
	            <input class="layui-input" type="password" name="password" id="password" placeholder="密码">
	        </div>
			
	        <div class="layui-form-item captcha-item">
	            <label class="layui-icon layui-icon-vercode"></label>
	            <input class="layui-input" type="text" name="code" autocomplete="off" placeholder="验证码">
	            <div >
					<img id="addPic" class="captcha-img" src="${pageContext.request.contextPath}/admin/validateCode" width="96" height="27"
						 onclick="this.src='${pageContext.request.contextPath}/admin/validateCode?r='+Math.random();"/>
				</div>
	        </div>
			<span id="msg"></span>
	        <button type="button" class="layui-btn layui-btn-fluid ajax-login"><i class="fa fa-sign-in fa-lg fa-fw"></i> 登录</button>
	    </form>
	</div>
	</body>
	<script type="text/javascript">
		$(function () {
			$("button").click(function () {
				var username = $("input[name=username]").val();
				var password = $("input[name=password]").val();
				var code = $("input[name=code]").val();
				if(code == ''){code="~~~";}
				$.ajax({
					url: "${pageContext.request.contextPath}/admin/login/"+code,
					data:'{"username":"'+username+'","password":"'+password+'"}',
					type:"post",
					dataType:"json",
					contentType:"application/json",
					success:function (result) {
						if(result.status == "success"){
							//登录成功，跳转到主界面
							location.href="${pageContext.request.contextPath}/main.jsp";
						}else{
							//登录失败，回显错误信息
							$("#msg").html(result.msg);
						}
					}
				});

			})
		})
	</script>
</html>
